/*
 * ©2023 JOY-HUBS.COM
 */

package com.joyhubs.app.application.controller;

import java.util.Date;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import static com.joyhubs.base.constants.Constants.RESPONSE_CONTENT_TYPE;

import com.joyhubs.base.exception.BizException;
import jakarta.validation.Valid;

/**
 * microservice quick start demo controller, can be removed in production.
 */
@Tag(name = "QuickStart")
@RestController
@RequestMapping("/quick")
public class QuickStartController {
    
    @Operation(summary = "simple http request")
    @GetMapping(value = "/start", produces = RESPONSE_CONTENT_TYPE)
    public String start() {
        return String.format("This is a quick start of microservice");
    }
    
    @Operation(summary = "parameter valid request")
    @GetMapping(value = "/hello", produces = RESPONSE_CONTENT_TYPE)
    public String hello(@Valid @RequestParam(name = "username") String username) {
        return String.format("Hello, %s", username);
    }
    
    @Operation(summary = "business exception request")
    @GetMapping(value = "/exception", produces = RESPONSE_CONTENT_TYPE)
    public ResponseEntity bizException() {
        throw new BizException("1000", "this is a biz exception");
    }
    
    @Operation(summary = "default content-type request")
    @GetMapping(value = "/content-type")
    public String defaultContentType() {
        return "response from default content-type";
    }
    
    @Operation(summary = "object response wrapper request")
    @GetMapping(value = "/time")
    public Date time() {
        return new Date();
    }
    
}
